package collection;

import classics.Array;

import java.util.*;

public class ArrayListDemo {
    public static void main(String[] args) {
        //ArrayList构造和添加方法 追加 插入 添加指定集合全部元素
        ArrayList<String> arrayList = new ArrayList<>();

        arrayList.add("刘德华");
        arrayList.add("章子怡");
        arrayList.add("刘浩存");
        System.out.println(arrayList);

        arrayList.add(1,"赵丽颖");
        System.out.println(arrayList);

        ArrayList<String> arrayList1 = new ArrayList<>();
        arrayList1.add("宋小宝");
        arrayList1.add("小沈阳");
        System.out.println(arrayList1);
        System.out.println(arrayList.addAll(arrayList1));
        System.out.println(arrayList);

        //Array集合常用方法
        arrayList.remove("章子怡");//删除指定元素
        System.out.println(arrayList.remove(1));;//删除指定索引处元素
        System.out.println(arrayList);
        System.out.println(arrayList.set(0,"赵丽颖"));//取代指定索引处元素
        System.out.println(arrayList.get(0));//获取指定索引处元素
        System.out.println(arrayList.size());//获取元素个数
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 11; i++) {
            list.add(i*10);
        }
        System.out.println("list:"+list);
        List<Integer> list1 = list.subList(0,5);
        list1.remove(0);
        System.out.println(list);
        for (int i = 0; i < list1.size(); i++) {
            System.out.println( "list1:"+list1.set(i,list1.get(i)*10));;
        }
        System.out.println("list:"+list);

    }
}
